package cn.tedu.oop;

import java.util.Arrays;

/**
 * @author SWJ
 * @create 2021-06-07 17:24
 */
public class TestBubbleSort {
    public static void main(String[] args) {
        //创建一个乱序数组
        int[] a = new int[]{45, 32, 65, 6, 7, 8, 9, 9,};
        //进行排序
        /*使用嵌套for循环完成排序*/
        //2.外层循环控制的轮数 控制的比较轮数n个数 最多比较n-1轮
        //循环就近执行几次 取决循环变量i可以取到几个数值
        for (int i = 1; i <= a.length - 1; i++) {
            //内层循环 控制每轮循环次数
            for (int j = 0; j < a.length-i; j++) {
                //遍历数组 a.length是比较出来的最大值
                //j代表的数组下标 下标从0开始
                //比较相邻的数 只要位置不对就互换
                //前面数是a[j] 后面数是a[j+1]
                if (a[j]>a[j+1]){
                    int t=a[j];
                    a[j]=a[j+1];
                    a[j+1]=t;
                }
            }
        }
        System.out.println(Arrays.toString(a));
    }
}
//"C:\Program Files\Java\jdk1.8.0_91\bin\java.exe" "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2020.2.3\lib\idea_rt.jar=61262:D:\Program Files\JetBrains\IntelliJ IDEA 2020.2.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_91\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\rt.jar;E:\idea\Java Module\out\production\Java Module" cn.tedu.oop.TestCreateClass.TestBubbleSort
//        [6, 7, 8, 9, 9, 32, 45, 65]
//
//        Process finished with exit code 0